package com.loan.service;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.jfinal.plugin.activerecord.Page;
import com.loan.enums.InvestLogType;
import com.loan.model.InvestLog;

public class InvestLogService extends BaseService<InvestLog>{

	/**
	 * 新增交易记录
	 */ 
	public static void build(String name, InvestLogType type, double amount, int userId, String summary) {
		InvestLog log = new InvestLog();
		log.setName(name);
		log.setMode(type.getMode());
		log.setType(type.getType());
		log.setAmount(amount);
		log.setUserId(userId);
		log.setCreateTime(new Date());
		log.setStatus("success");
		log.setSummary(summary);
		log.save();
	}
	
	/** 
	 * 分页数据
	 */
	public Page<InvestLog> list(Map<String, String> map) {
		return this.list(Integer.valueOf(map.getOrDefault("page", "1")), Integer.valueOf(map.getOrDefault("size", "10")), map);
	}
	
	/** 
	 * 分页数据
	 */
	public Page<InvestLog> list(int page, int size, Map<String, String> map) {
		return InvestLog.dao.paginate(page, size, buildSql("invest_log",Arrays.asList("user_id", "type", "name", "status"),map," order by create_time desc "));
	}
}
